[core/swarm] Refactor and extend configurable connection limits.#1848
Merged
romanb merged 6 commits intolibp2p:masterfrom Nov 23, 2020
Merged
[core/swarm] Refactor and extend configurable connection limits.#1848romanb merged 6 commits intolibp2p:masterfrom
romanb merged 6 commits intolibp2p:masterfrom
Conversation
added 2 commits
November 20, 2020 13:27
To better track different connection counts, permit configurable limits for these counts and make these available for inspection efficiently, introduce dedicated connection counters via a `ConnectionCounters` structure that is exposed on the API via the `NetworkInfo`. All connection or connection states that are counted in this way can also have effective configurable limits.
mxinden
reviewed
Nov 23, 2020
Member
mxinden
left a comment
There was a problem hiding this comment.
Good catch on the iterator state mismatch!
tomaka
approved these changes
Nov 23, 2020
Member
tomaka
left a comment
There was a problem hiding this comment.
Looks good to me with the same remarks as Max on the naming.
Contributor
Author
|
I incorporated the naming suggestion(s) in 4e447e9 together with a bit of refinement for the configuration APIs:
The |
mxinden
approved these changes
Nov 23, 2020
Member
mxinden
left a comment
There was a problem hiding this comment.
Both the connection limiting as well as the general API improvements look good to me.
Co-authored-by: Max Inden <mail@max-inden.de>
Co-authored-by: Max Inden <mail@max-inden.de>
This was referenced Nov 24, 2020
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The initial motivation for the work in this PR is #1839. However, the PR goes a bit further than to just add a single counter to have a more streamlined API. Thus, in order to better track different connection counts and permit configurable limits for these counts and make these available for inspection in an efficient manner (i.e. without linear counting operations), I introduced dedicated connection counters via a
ConnectionCountersstructure maintained by the internal connection pool but exposed on the API via theNetworkInfo. All connection states that are counted in this way can also have effective configurable limits.All limits are now configured through a
ConnectionLimitsstructure. The new configurable limits areConnectionLimits::max_established_incomingfor limiting the number of concurrent established connections that were incoming.ConnectionLimits::max_established_outgoingfor limiting the number of concurrent established connections that were outgoing.A limit that has been removed because tracking the related counts efficiently would be a bit laborious and I don't think it is particularly useful is
NetworkConfig::set_outgoing_per_peer_limit()Note that there are still the pre-existing
ConnectionLimits::max_incomingandConnectionLimits::max_outgoingwhich correspond to the two new configuration options above, just for pending connections. I also took the liberty to change the connection limits to useu32instead ofusizefor their types, which seems more appropriate.Fixed panic in the
PeerAPIThe
Network::peer()API allows to iterate mutably over the ongoing connection attempts viaDialingPeer::attempts(), where eachDialingAttemptcan beabort()ed during iteration. However, the iterator did not take into account the changes to the internal iteration offsets when elements are removed. This was discovered while extending the connection limit tests a bit and has been fixed now as a result.